package com.tengju.user.infrastructure.repository;

import com.tengju.user.domain.model.user.Staff;
import com.tengju.user.domain.model.user.StaffId;
import com.tengju.user.domain.model.user.UserStaffRepository;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.UserStaffDO;
import com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.custom.UserStaffDOCustomMapper;
import com.tengju.user.infrastructure.repository.convert.StaffInfoConvert;
import javax.annotation.Resource;
import org.springframework.stereotype.Repository;

/**
 * @author wuziyang
 */
@Repository
public class UserStaffRepositoryImpl implements UserStaffRepository {

    @Resource
    UserStaffDOCustomMapper userStaffDOCustomMapper;

    @Override
    public Staff queryUserStaff(StaffId staffId) {

        UserStaffDO userStaffDO = userStaffDOCustomMapper.selectByStaffId(staffId.getValue());
        return StaffInfoConvert.convertStaffDOToStaff(userStaffDO);

    }

    @Override
    public StaffId store(Staff staff) {
        UserStaffDO userStaffDO = StaffInfoConvert.convertStaffToStaffDO(staff);
        userStaffDOCustomMapper.insert(userStaffDO);
        return new StaffId(userStaffDO.getStaffId());
    }

}
